Repository navigation
Conversation
…rmat DecimalCodec.EncodeDecimal wrote coefficients with more digits than the format allows, and exponents outside its range, without any check (only a Debug.Assert). In Release builds the excess bits overflowed into the combination/exponent fields and the server stored a different value, e.g.: 12345678901234567890123456789012345 -> DECFLOAT(34) stored 8345678901234567890123456789012345 30000000000000004E-17 -> DECFLOAT(16) stored 0.08000000000000004 1E400 -> DECFLOAT(16) stored 8.000000000000001E-353 The encoder now brings the value into the format's ranges without changing its numeric value (dropping trailing zeros of the coefficient, folding the exponent into the coefficient, clamping the exponent of zero), and throws OverflowException when the value cannot be represented exactly (too many significant digits, exponent overflow or underflow). Values that previously got corrupted although representable (e.g. 1E384 in DECFLOAT(16)) now work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1298.
Summary
DecimalCodec.EncodeDecimalsilently corrupted DECFLOAT values whose coefficient or exponent does not fit the target format; only aDebug.Assertchecked it. The encoder now brings the value into the format's ranges without changing its numeric value, or throwsOverflowException.Changes
DecimalCodec.FitToFormat(used byEncodeFinite):12345678901234567890123456789012340fitsDECFLOAT(34)),1E384becomes1000000000000000E369inDECFLOAT(16)),100E-400becomes1E-398),OverflowException("cannot be represented exactly as DECFLOAT(n)") when none of that is possible, i.e. when the value would have to be rounded, or overflows or underflows the format.DecimalCodecis used by both the managed and the native client, so both are fixed.Tests
DecimalCodecTests(NoServer) covers, for both formats:FbDecFloat16SupportTestsandFbDecFloat34SupportTests:PassesUnrepresentableValueThrows, which also checks that the connection stays usable afterwards.